<?php

    class JenisKegiatan extends CI_Model
    {
        private $typeID;
        private $typeName;

        // Konstruktor
        public function JenisKegiatan_model() {
            parent::Model();
        }

        // Getter dan Setter Biasa
        public function getTypeId() {
            return $this->typeID;
        }

        public function setTypeId($typeID) {
            $this->typeID = $typeID;
        }

        public function getTypeName() {
            return $this->typeName;
        }

        public function setTypeName($typeName) {
            $this->typeName = $typeName;
        }

        // Operasi Data
        public function getAllJenisKegiatan() {
            $query = $this->db->get('jeniskegiatan');
            return $query->result();
        }

        public function getJenisKegiatan($typeID) {
            $query = $this->db->get_where('jeniskegiatan',
                    array('typeID' => $typeID), 1, 0);
            return $query->row();
        }

        public function insertJenisKegiatan() {
            $data = array(
                'typeID' => $this->typeID,
                'typeName' => $this->typeName
            );
            $this->db->insert('jeniskegiatan',$data);
        }

        public function changeJenisKegiatan($jenisKegiatan) {
            $this->db->where('typeID', $this->typeID);
            $this->db->update('jeniskegiatan', $jenisKegiatan);
        }

        public function deleteJenisKegiatan() {
            $this->db->trans_start(TRUE); // Query akan di-rollback jika gagal
            $this->db->delete('jeniskegiatan', array('typeID' => $this->typeID));
            $this->db->query("ALTER TABLE jeniskegiatan AUTO_INCREMENT=1");
            //reset auto-numbering
            $this->db->trans_complete();
        }
    }
?>